<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title am-fl">首次转化统计</div>
        </div>
        <div class="widget-body  am-fr">
          <customer-toolbar ref="toolbar"  class="toolbar" @search="handleFind"  @export="handleExport"
            areaTeam campusTeam hasExport alloCreateTime counselorName firstRegTime
          ></customer-toolbar>
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              maxHeight="600"
              empty-text="暂无数据"
              stripe
              style="min-width: 100%">
              <el-table-column
                min-width="100"
                prop="studentName"
                label="学生姓名">
              </el-table-column>
              <el-table-column
                min-width="130"
                prop="phoneNo"
                label="联系电话">
              </el-table-column>
               <el-table-column
                min-width="150"
                prop="areaTeamName"
                label="区域">
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="campusName"
                label="分配校区">
              </el-table-column>
              <el-table-column
                min-width="130"
                prop="projectName"
                label="项目活动名称">
              </el-table-column>
               <el-table-column
                min-width="165"
                label="分配时间">
                <template scope="scope">
                  <div>{{scope.row.alloCreateTime | formatTime}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="bigCategory"
                label="来源大类">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="smallCategory"
                label="来源小类">
              </el-table-column>
              <el-table-column
                min-width="165"
                label="资源类别">
                <template scope="scope">
                  <div>{{scope.row.customerResourceType === '0'?'旧资源':'新资源'}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="165"
                prop="departmentName"
                label="导入部门" >
              </el-table-column>
               <!-- <el-table-column
                min-width="165"
                prop="importOperatorName"
                label="导入人" >
              </el-table-column> -->
              <el-table-column
                min-width="100"
                prop="gradeName"
                label="学生年级">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="areaTeamName"
                label="跟进状态">
                <template scope="scope">
                  <div>{{scope.row.visitStatus === '0' ? '未跟进' : '已跟进'}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="165"
                label="首次成交时间">
                <template scope="scope">
                  <div>{{scope.row.firstRegTime | formatTime}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="firstRegNum"
                label="首次成交科数">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="firstRegAmount"
                label="首次成交金额">
              </el-table-column>
               <el-table-column
                min-width="100"
                prop="followOperatorName"
                label="抢占人">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="counselorNames"
                label="咨询师">
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="am-u-lg-12 am-cf">
          <div class="am-fr">
            <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                        @paging="loadTableData"/>
          </div>
        </div>
        <dispatch-detail @completed="loadTableData" ref="dispatchDetail"></dispatch-detail>
      </div>
    </div>
  </div>
</template>
<script>
  import io from '../../lib/io'
  import CustomerToolbar from './CustomerToolbar.vue'
  import Pagination from '../base/Pagination.vue'
  import moment from 'moment'
  import DispatchDetail from './DispatchDetail.vue'

  export default{
    data:function(){
      return {
        total: 0,
        pageSize: 10,
        pageNo: 1,
        tableData: [],
      }
    },
    components: {
      CustomerToolbar, Pagination, DispatchDetail
    },
    mounted :function(){
      $(window).smoothScroll()
    },
    methods:{

      handleFind(formData) {
        this.formData = this.formatData(formData)
        this.loadTableData(1)
      },
      handleExport(){
        let param  = this.formData
        io.downloadFile(io.exportFirstRegOfCustomerResource,param,(ret)=>{})
      },
      loadTableData: function (pageNo) {
        this.pageNo = pageNo || this.pageNo || 1
        this.$showLoading()
        io.post(io.firstRegOfCustomerResource, Object.assign({}, this.formData, {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
        }), (ret) => {
          this.$hiddenLoading()
          if (ret.success) {
            this.tableData = ret.data.list
            this.total = ret.data.total
          } else {
            this.$alert(ret.desc)
          }
        })
      },
      formatData(data) {
        return {
            areaTeamId: data.areaTeamId,
            campusId: data.campusId,
            counselorName:data.counselorName,
            alloCreateTimeOfStart: data.alloCreateTime[0] ? moment(data.alloCreateTime[0]).format('YYYY-MM-DD') + " 00:00:00" : '',
            alloCreateTimeOfEnd: data.alloCreateTime[1] ? moment(data.alloCreateTime[1]).format('YYYY-MM-DD') + " 23:59:59" : '',
            firstRegTimeOfStart:data.firstRegTime[0] ? moment(data.firstRegTime[0]).format('YYYY-MM-DD') + " 00:00:00":'',
            firstRegTimeOfEnd:data.firstRegTime[1] ? moment(data.firstRegTime[1]).format('YYYY-MM-DD') + " 23:59:59":'',
        }
      }
    }
  }
</script>
<style lang="less" scoped>
</style>
